{extend name="public/base" /}
{block name="button"}
<button data-modal='{:url("add")}' data-title="添加分类" class='layui-btn layui-btn-sm layui-btn-primary'>添加分类</button>
{/block}
{block name="content"}
<form class="layui-form layui-form-pane form-search" action="{:url()}" onsubmit="return false" method="post" autocomplete="off">
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">分类名称</label>
        <label class="layui-input-inline">
            <input name="name" value="" placeholder="" class="layui-input">
        </label>
    </div>
    <div class="layui-form-item layui-inline">
        <label class="layui-form-label">状态</label>
        <div class="layui-input-inline">
            <select name="status" lay-search class="layui-select">
                <option value='0'>全部</option>
                <option value='1'>启用</option>
                <option value='-1'>禁用</option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-inline">
        <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i>搜索</button>
    </div>
</form>
<table id="CategoryTable"  data-url="{:url('index')}" data-target-search="form.form-search"></table>
{/block}
{block name='script'}
<script>
    $(function () {
        $('#CategoryTable').layTable({
            even: true,
            height: 'full',
            method: 'post',
            sort: {field: 'sort desc,id', type: 'desc'},
            url: "{:url('index')}" ,
            page: true,
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'id', title: 'id', width: 100, align: 'center'},
                {field: 'name', title: '分类名称', minWidth: 100, align: 'center', templet: '<div>{{d.name||"-"}}</div>'},
                {field: 'status', title: '状态', align: 'center', minWidth: 110, templet: '#StatusSwitchTpl'},
                {field: 'sort', title: '排序', align: 'center', minWidth: 100, sort: true},
                {field: 'create_at', title: '创建', align: 'center', minWidth: 170, sort: true},
                {field: 'update_at', title: '更新时间', align: 'center', minWidth: 170, sort: true},
                {field: 'create_operator', title: '创建人账户', align: 'center', minWidth: 170, sort: true},
                {field: 'update_operator', title: '更新人账户', align: 'center', minWidth: 170, sort: true},
                {toolbar: '#toolbar', title: '操作面板', align: 'center', minWidth: 180, fixed: 'right'}
            ]]
        });
        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (obj) {
            var data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : -1};
            $.form.load("{:url('status')}", data, 'post', function (ret) {
                if (ret.code >1) $.msg.error(ret.msg, 3, function () {
                    $('#CategoryTable').trigger('reload');
                }); else {
                    $('#CategoryTable').trigger('reload')
                }
                return false;
            }, false);
        });
        $.menu.highlight_subnav("{:url('index')}")
    });
</script>

<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="已激活|已禁用" lay-filter="StatusSwitch" {{-d.status==1?'checked':''}}>
    {{-d.status==1 ? '<b class="color-green">已激活</b>' : '<b class="color-red">已禁用</b>'}}
</script>

<script type="text/html" id="toolbar">
    <a class="layui-btn layui-btn-sm" data-event-dbclick data-title="编辑" data-modal='{:url("edit")}?id={{d.id}}'>编 辑</a>
</script>
{/block}
